package com.example.leepong.Game.Utils;

import android.util.Log;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by Ichigo on 02/03/14.
 */
public class PerfsMonitor {

    private static HashMap<String, ArrayList<Long>> dico = new HashMap<>();

    public static void Monitor(String key, int displayEach, Runnable runnable) {
        Long start = System.currentTimeMillis();
        runnable.run();
        Long frameTime = System.currentTimeMillis() - start;

        ArrayList<Long> values = dico.get(key);
        if (values == null) {
            values = new ArrayList<Long>();
        }

        values.add(frameTime);
        dico.put(key, values);
        if (values.size() == displayEach) {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < displayEach; i++) {
                sb.append("|" + values.get(displayEach - (i + 1)));
                if (i == 40)
                    break;
            }

            Log.d("Monitor:" + key, sb.toString());
            values.clear();
        }
    }
}
